networkx: All return types from python-type-stubs#14256
Merged
srittau merged 7 commits intopython:mainfrom Jul 8, 2025
Merged
Conversation
…kx-return-type-annotations-from-python-type-stubs
…' of https://github.com/Avasam/typeshed into networkx-return-type-annotations-from-python-type-stubs
This comment has been minimized.
This comment has been minimized.
srittau
requested changes
Jul 7, 2025
Collaborator
srittau
left a comment
There was a problem hiding this comment.
Just two small remarks below.
| def write_edgelist(G, path, comments: str = "#", delimiter: str = " ", data: bool = True, encoding: str = "utf-8") -> None: ... | ||
| @_dispatchable | ||
| def generate_edgelist(G, delimiter: str = " ", data: bool = True) -> Generator[Incomplete, None, None]: ... | ||
| def generate_edgelist(G, delimiter: str = " ", data: bool = True) -> Generator[str, None, None]: ... |
Collaborator
There was a problem hiding this comment.
Nitty nit:
Suggested change
| def generate_edgelist(G, delimiter: str = " ", data: bool = True) -> Generator[str, None, None]: ... | |
| def generate_edgelist(G, delimiter: str = " ", data: bool = True) -> Generator[str]: ... |
Collaborator
Author
There was a problem hiding this comment.
(applied suggestion)
There's a ton of those in networkx stubs. Maybe we should have a lint rule for the new concise Generator format ?
| weight: str | None = "weight", | ||
| format="csr", | ||
| ): ... | ||
| ): ... # Return is a complex union of scipy classes depending on the format param |
Collaborator
There was a problem hiding this comment.
So, should we return Any?
Suggested change
| ): ... # Return is a complex union of scipy classes depending on the format param | |
| ) -> Any: ... # Return is a complex union of scipy classes depending on the format param |
Collaborator
Author
There was a problem hiding this comment.
I think I added this comment initially because I probably added Any as well, but I think you could actually represent the return type with overloads based on the format param. So it's more "incomplete", than "unrepresentable".
Co-authored-by: Sebastian Rittau <[email protected]>
srittau
approved these changes
Jul 8, 2025
Contributor
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Extracted from #14038
Return types are a lot more straightforward to validate. So I extracted them in their own PR to reduce the size of #14038